<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('is_logged_in')){
	function is_logged_in($show_error = false){
		$CI =& get_instance();
		load_lang_file('users');
		if(!$CI->session->userdata('username')){
			if($show_error == true){
				$data['error_msg'] = sprintf(
					$CI->lang->line('must_login'), 
					'<a href="'.site_url('login/').'">'.$CI->lang->line('must_login_link_title')."</a>"
				);
				$CI->load->view('error', $data);
			}
			return false;
		}
		return true;
	}
}
if ( ! function_exists('has_sufficient_role_to')){
    function user_has_sufficient_role_to($action){
        $CI =& get_instance();
        $CI->config->load('users');
        $sufficient_role = $CI->config->item($action);
        if($CI->session->userdata('role') <= $sufficient_role){
            return true;
        } else {
            return false;
        }
    }
}